package com.huanong.controller.impl;
/*
 *@Author:anran
 *@Date:2020/12/7
 *@Version 1.0
 */

import com.huanong.common.grace.result.GraceJSONResult;
import com.huanong.controller.CompanyControllerApi;
import com.huanong.pojo.Company;
import com.huanong.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CompanyController implements CompanyControllerApi {
    @Autowired
    private CompanyService companyService;

    @Override
    public GraceJSONResult query() {
        List<Company> list=companyService.query();
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult queryById(Integer CyId) {
        Company company=companyService.queryById(CyId);
        return GraceJSONResult.ok(company);
    }

    @Override
    public GraceJSONResult add(Company company) {
        int flag=companyService.add(company);
        if (flag==1){
            return GraceJSONResult.ok("添加公司介绍信息成功");
        }
        return GraceJSONResult.errorMsg("添加公司介绍信息失败");
    }

    @Override
    public GraceJSONResult delete(Integer CyId) {
        int flag=companyService.delete(CyId);
        if (flag!=0){
            return GraceJSONResult.ok("删除公司信息成功");
        }
        return GraceJSONResult.errorMsg("删除公司信息失败");
    }

    @Override
    public GraceJSONResult update(Company company) {
        int flag=companyService.update(company);
        if (flag!=0){
            return GraceJSONResult.ok("更新公司介绍信息成功");
        }else {
            return GraceJSONResult.errorMsg("更新公司介绍信息失败");
        }
    }

    @Override
    public GraceJSONResult queryNewMessage() {

        Company newCompany = companyService.queryNewMessage();

        return GraceJSONResult.ok(newCompany);
    }
}
